package hot100;

import comment.ListNode;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-18  10:16
 * @Description: 反转链表
 * @Version: 1.0
 */
public class hot_206 {
    ListNode result=null;
    public ListNode reverseList(ListNode head) {
        result=null;
        if(head==null||head.next==null){
            return head;
        }
//        先处理第一个节点
        ListNode index=head.next;
        head.next=null;
        dfs(head,index);
        return result;
    }

    public void dfs(ListNode before,ListNode index){
        if(index==null){
            result=before;
            return;
        }
        ListNode next=index.next;
        index.next=before;
        before=index;
        dfs(before,next);

    }
}
